package com.liaoyifan.core.query;

import com.liaoyifan.core.valid.groups.Opera;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import java.io.Serializable;
import lombok.Data;

@SuppressWarnings("unused")
@Data
public class PageQuery implements Serializable {

    @Serial private static final long serialVersionUID = 1L;

    @Schema(description = "页大小")
    @Max(value = 5000, groups = Opera.Page.class) @NotNull(groups = Opera.Page.class) private Long limit;

    @Schema(description = "当前页")
    @Min(value = 1, groups = Opera.Page.class) @NotNull(groups = Opera.Page.class) private Long current;

    @Schema(hidden = true)
    public Long getStart() {
        return this.current != null && this.limit != null ? (this.current - 1L) * this.limit : null;
    }
}
